package ai.people.platform.archives.ws.scheduler;

import ai.people.platform.archives.ws.context.WsSessionContext;
import ai.people.platform.information.timer.TimerSingletonHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.TimeUnit;

/**
 * @author LiGuanNan
 * @date 2022/7/18 16:32
 */
@Slf4j
@Component
public class SessionKeepAliveScheduler {

    @PostConstruct
    public void init(){
        keepAliveSessions();
    }

    public void keepAliveSessions(){
        TimerSingletonHolder.getTimerInstance().newTimeout(timeout->{
            WsSessionContext.keepAliveSessions();
            timeout.timer().newTimeout(timeout.task(), 30, TimeUnit.SECONDS);
        },30, TimeUnit.SECONDS);
    }
}
